package com.atguigu.tingshu.user.config;

import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl;
import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Data
@Configuration
@ConfigurationProperties(prefix = "wechat.login")
public class WechatAccountConfig {

    private String appId;

    private String appSecret;

    @Bean
    public WxMaService getWxMaSetting() {

        // 使用微信接口服务所对应SDK, 请求微信接口服务的校验登录凭证接口，完成code校验
        WxMaDefaultConfigImpl wxMaConfig = new WxMaDefaultConfigImpl() ;
        wxMaConfig.setAppid(appId);
        wxMaConfig.setSecret(appSecret);
        WxMaService wxMaService = new WxMaServiceImpl() ;
        wxMaService.setWxMaConfig(wxMaConfig);

        return wxMaService ;
    }
}
